﻿//父控制器
app.controller("pageCtrl", function($scope) {
	//每个页面的顶部栏参数
	$scope.page={
		topOpen:true,
		title:'',
		leftNav:'',
		rightNav:''
	}
	
	
});

//协议
app.controller('agreementCtrl',function($scope,$http,$rootScope){
	$scope.page.topOpen=true;
	$scope.page.bottomOpen=false;
	$scope.page.title='会员注册';
	$scope.page.leftNav='sqbackcom';
	$scope.page.rightNav='';
	
	$scope.page.agimg1=resUrl+'wx_assets/hn/images/ag_image1.png'+version;
	$scope.page.agimg2=resUrl+'wx_assets/hn/images/aghn.png'+version;
	
	var _u=buildUrl('json',"hn",'agreement',{});
	
	$http.get(_u).success(function(data){
		$scope.innerHtml=data.content;
		$rootScope.callSuccessHttp();
	})
	
})


app.controller('regs1Ctrl',function($scope,$http,$rootScope,BasicData,$cookieStore){
	$scope.page.topOpen=true;
	$scope.page.bottomOpen=false;
	$scope.page.title='个人资料';
	$scope.page.leftNav='sqbackcom';
	$scope.page.rightNav='';
	
	
	$scope.model={
		tmp:'',
		minTmp:'',
		maxTmp:''
	}
	
	$scope.page.agimg2=resUrl+'wx_assets/hn/images/aghn.png'+version;
	
	$scope.fm_list=[
		{
			id:'realname',
			name:"姓名",
			type:"input"
		},
		{
			id:'birthday',
			name:"生日",
			type:"date",
			value:"未填写"
		},
		{
			id:'phone',
			name:"手机号",
			type:"input"
		},
		{
			id:'weixin',
			name:"微信号",
			type:"input"
		},
		{
			id:'gender',
			name:"性别",
			type:'select',
			option:[
				{name:'未选择',id:0},
				{name:'男',id:1},
				{name:'女',id:2}
			],
			value:'0'
		},
		{
			id:'height',
			name:"身高",
			type:"select",
			standard:true,
			option:(function(){
				var _option=new Array();
				for(var i=_heightStart;i<=_heightEnd;i++)
				{
					var tmp=new Object();
					if(i==_heightStart)
					{
						tmp.name='未选择';
						tmp.id=0;
					}
					else
					{
						tmp.name=i+'CM';
						tmp.id=i;
					}
					_option.push(tmp)
				}
				return _option;
			})(),
			value:'0'
		},
		{
			id:'weight',
			name:"体重",
			type:"select",
			standard:true,
			option:(function(){
				var _option=new Array();
				for(var i=_weightStart;i<=_weightEnd;i++)
				{
					var tmp=new Object();
					if(i==_weightStart)
					{
						tmp.name='未选择';
						tmp.id=0;
					}
					else
					{
						tmp.name=i+'KG';
						tmp.id=i;
					}
					_option.push(tmp)
				}
				return _option;
			})(),
			value:'0'
		},
		{
			id:'education',
			name:"学历",
			type:'select',
			option:[
				{name:"未选择",id:0},
				{name:"大专以下",id:1},
				{name:"大专",id:2},
				{name:"本科",id:3},
				{name:"硕士",id:4},
				{name:"博士",id:5}
			],
			value:'0'
		},
		{
			id:'job',
			name:"职业",
			type:'select',
			option:[
				{name:'未选择',id:0},
				{name:'计算机/互联网/通信',id:1},
				{name:'公务员/事业单位',id:2},
				{name:'教师',id:3},
				{name:'医生',id:4},
				{name:'护士',id:5},
				{name:'空乘人员',id:6},
				{name:'生产/工艺/制造',id:7},
				{name:'商业/服务业/个体经营',id:8},
				{name:'金融/银行/投资/保险',id:9},
				{name:'文化/广告/传媒',id:10},
				{name:'娱乐/艺术/表演',id:11},
				{name:'律师/法务',id:12},
				{name:'教育/培训/管理咨询',id:13},
				{name:'建筑/房地产/物业',id:14},
				{name:'酒店/旅游',id:15},
				{name:'农业',id:16},
				{name:'在校学生',id:17}
			],
			value:'0'
		},
		{
			id:'earning',
			name:"年收入",
			type:"select",
			standard:true,
			option:(function(){
				var _option=new Array();
				for(var i=_earningStart;i<=_earningEnd;i++)
				{
					var tmp=new Object();
					if(i==_earningStart)
					{
						tmp.name='未选择';
						tmp.id=0;
					}
					else
					{
						tmp.name=i+'万';
						tmp.id=i;
					}
					_option.push(tmp)
				}
				return _option;
			})(),
			value:'0'
		},
		{
			id:'province',
			name:"省份",
			type:'select',
			option:(function(){
				var arr=new Array(),tmp=new Object();
				for(var i=0;i<provinceArr.length;i++)
				{
					arr.push({
						name:provinceArr[i],
						id:i+1
					})
				}
				return arr;
			})(),
			value:'省份'
		},
		{
			id:'city',
			name:"城市",
			type:'select',
			value:'市县'
		}
	]
	
	if($rootScope.uiObj.rebuildBase==1)
	{
		var BasicData=JSON.parse(_USERINFO);
	}
	else
	{
		var BasicData=$cookieStore.get("BasicData")
	}
	
	if(BasicData)
	{
		var cd=BasicData;
	
		var tmp=[];
		for(var key in cd){
		   //key是属性,object[key]是值
		   tmp.push(key);//往数组中放属性
		}
		
		for(var i=0;i<tmp.length;i++)
		{
			var id=tmp[i];
			
			for(var y=0;y<$scope.fm_list.length;y++)
			{
				if($scope.fm_list[y].id==id)
				{

					$scope.fm_list[y].value=cd[id];
					
				}
			}
		}
	}
	
	$scope.initcity=function(ischange){
		var _index;
		for(var i=0;i<provinceArr.length;i++)
		{
			if(provinceArr[i]==matchobj('province',$scope.fm_list).value)
			{
				_index=i;
			}
		}
		$scope.page.citylist=cityArr[_index];
		console.log(matchobj('city',$scope.fm_list).value);
		if(ischange)
		{
			matchobj('city',$scope.fm_list).value=$scope.page.citylist[0];
		}
		else if(matchobj('city',$scope.fm_list).value=="f")
		{
			matchobj('city',$scope.fm_list).value='市县'
		}
		console.log(cityArr);
		
	}
	$scope.initcity();
	
	
	
	$scope.changeCity=function(id,ev){
		console.log(ev);
		if(id=='province')
		{
			$scope.initcity(true);
		}
	}
	
	$scope.checkform=function(){
		for(var i=0;i<$scope.fm_list.length;i++)
		{
			console.log($scope.fm_list[i].value)
			if(!$scope.fm_list[i].value||$scope.fm_list[i].value=='未填写'||$scope.fm_list[i].value=='0')
			{
				alert('请填写'+$scope.fm_list[i].name)
				return false;
			}
			else if($scope.fm_list[i].id=='province')
			{
				if($scope.fm_list[i].value=='省份')
				{
					alert('请选择'+$scope.fm_list[i].name)
					return false;
				}
			}
		}
		return true;
	}
	
	$scope.finished=function(){
		$rootScope._nextStep($scope.checkform(),$scope.fm_list,function(obj){
			$rootScope.uiObj.layerloadingCtrl=true;
			var _u=buildUrl('json',"hn",'regLover',obj);
			
			$http.get(_u).success(function(data){

				$rootScope.callSuccessHttp();
				if(data.code==0||data.code)
				{
					isbase=1;
					layer.open({
						content:'注册成功'
					})
					setTimeout(function(){
						location.reload();
//						window.location.href=serhost+'call.html?module=hn&method=index&customerId='+_customerId+'#/pindex/0';
					},1500)
					
				}
				else
				{
					layer.open({
						content:data.msg
					})
				}
				
			})
		});
	}
	
	$scope.nextStep=function(){
		$rootScope._nextStep($scope.checkform(),$scope.fm_list);
	}
	
	$rootScope.callSuccessHttp();
})

app.controller('regs2Ctrl',function($scope,$http,$rootScope,BasicData,$cookieStore){
	$scope.page.topOpen=true;
	$scope.page.bottomOpen=false;
	$scope.page.title='个人资料';
	$scope.page.leftNav='sqbackcom';
	$scope.page.rightNav='';
	
	$scope.model={
		tmp:'',
		minTmp:'',
		maxTmp:''
	}
	
	$scope.page.agimg2=resUrl+'wx_assets/hn/images/aghn.png'+version;
	
	$scope.fm_list=[
		{
			id:'house',
			name:"住房情况",
			type:'select',
			option:[
				{name:'未选择',id:'f'},
				{name:'无房',id:0},
				{name:'有房',id:1}
			],
			value:'f'
		},
		{
			id:'car',
			name:"购车情况",
			type:'select',
			option:[
				{name:'未选择',id:'f'},
				{name:'无车',id:0},
				{name:'有车',id:1}
			],
			value:'f'
		},
		{
			id:'onlyChild',
			name:"是否独生子女",
			type:'select',
			option:[
				{name:'未选择',id:'f'},
				{name:'独生子女',id:1},
				{name:'非独生子女',id:2}
			],
			value:'f'
		},
		{
			id:'religion',
			name:"宗教信仰",
			type:'select',
			option:[
				{name:'未选择',id:'f'},
				{name:'无宗教信仰',id:0},
				{name:'佛教',id:1},
				{name:'道教',id:2},
				{name:'基督教',id:3},
				{name:'伊斯兰教',id:4},
				{name:'其他',id:5}
			],
			value:'f'
		},
		{
			id:'registerProvince',
			name:"户口所在地(省)",
			type:'select',
			option:(function(){
				var arr=new Array(),tmp=new Object();
				for(var i=0;i<provinceArr.length;i++)
				{
					arr.push({
						name:provinceArr[i],
						id:i+1
					})
				}
				return arr;
			})(),
			value:'省份'
		},
		{
			id:'registerCity',
			name:"户口所在地(市)",
			type:'select',
			value:'市县'
		},
		{
			id:'nation',
			name:"民族",
			type:'select',
			option:[
				{name:'阿昌族',id:0},{name:'白族',id:1},{name:'保安族',id:2},{name:'布朗族',id:3},
				{name:'布依族',id:4},{name:'朝鲜族',id:5},{name:'达干尔族',id:6},{name:'傣族',id:7},
				{name:'德昂族',id:8},{name:'东乡族',id:9},{name:'侗族',id:10},{name:'独龙族',id:11},
				{name:'俄罗斯族',id:12},{name:'鄂伦春人',id:13},{name:'鄂温克族',id:14},{name:'高山族',id:15},
				{name:'仡佬族',id:16},{name:'哈尼族',id:17},{name:'哈萨克族',id:18},{name:'汉族',id:19},
				{name:'赫哲族',id:20},{name:'回族',id:21},{name:'基诺族',id:22},{name:'京族',id:23},
				{name:'景颇族',id:24},{name:'柯尔克孜族',id:25},{name:'拉祜族',id:26},{name:'黎族',id:27},
				{name:'傈僳族',id:28},{name:'珞巴族',id:29},{name:'满族',id:30},{name:'毛南族',id:31},
				{name:'门巴族',id:32},{name:'蒙古族',id:33},{name:'苗族',id:34},{name:'仫佬族族',id:35},
				{name:'纳西族',id:36},{name:'怒族',id:37},{name:'普米族',id:38},{name:'羌族',id:39},
				{name:'撒拉族',id:40},{name:'畲族',id:41},{name:'水族',id:42},{name:'塔塔尔族',id:43},
				{name:'塔吉克族',id:44},{name:'土家族',id:45},{name:'土族',id:46},{name:'佤族',id:47},
				{name:'维吾尔族',id:48},{name:'乌孜别克族',id:49},{name:'锡伯族',id:50},{name:'瑶族',id:51},
				{name:'彝族',id:52},{name:'裕固族',id:53},{name:'藏族',id:54},{name:'壮族',id:55}
			],
			value:'汉族'
		},
		{
			id:'constellation',
			name:"星座",
			type:'select',
			option:[
				{name:"未选择",id:'f'},
				{name:"摩羯",id:1},
				{name:"水瓶",id:2},
				{name:"双鱼",id:3},
				{name:"白羊",id:4},
				{name:"金牛",id:5},
				{name:"双子",id:6},
				{name:"巨蟹",id:7},
				{name:"狮子",id:8},
				{name:"处女",id:9},
				{name:"天秤",id:10},
				{name:"天蝎",id:11},
				{name:"射手",id:12}
			],
			value:'f'
		},
		{
			id:'shengxiao',
			name:"属相",
			type:'select',
			option:[
				{name:"未选择",id:'f'},
				{name:"鼠",id:1},
				{name:"牛",id:2},
				{name:"虎",id:3},
				{name:"兔",id:4},
				{name:"龙",id:5},
				{name:"蛇",id:6},
				{name:"马",id:7},
				{name:"羊",id:8},
				{name:"猴",id:9},
				{name:"鸡",id:10},
				{name:"狗",id:11},
				{name:"猪",id:12}
			],
			value:'f'
		},
		{
			id:'marital',
			name:"婚姻状况",
			type:'select',
			option:[
				{name:'未选择',id:'f'},
				{name:'未婚',id:1},
				{name:'离异无子女',id:2},
				{name:'离异不带子女',id:3},
				{name:'离异带子女',id:4},
				{name:'丧偶无子女',id:5},
				{name:'丧偶有子女',id:6},
			],
			value:'f'
		}
	]

	if($rootScope.uiObj.rebuildBase==1)
	{
		var BasicData=JSON.parse(_USERINFO);
	}
	else
	{
		var BasicData=$cookieStore.get("BasicData")
	}
	
	if($cookieStore.get("BasicData"))
	{
		var cd=$cookieStore.get("BasicData");
	
		var tmp=[];
		for(var key in cd){
		   //key是属性,object[key]是值
		   tmp.push(key);//往数组中放属性
		}
		
		for(var i=0;i<tmp.length;i++)
		{
			var id=tmp[i];
			
			for(var y=0;y<$scope.fm_list.length;y++)
			{
				if($scope.fm_list[y].id==id)
				{
					$scope.fm_list[y].value=cd[id];
					if($scope.fm_list[y].value=='')
					{
						
						if(id=='registerProvince')
						{
							$scope.fm_list[y].value='省份';
						}
						else
						{
							$scope.fm_list[y].value='f'
						}
					}
				}
			}
		}
	}
	$scope.initcity=function(ischange){
		var _index;
		for(var i=0;i<provinceArr.length;i++)
		{
			if(provinceArr[i]==matchobj('registerProvince',$scope.fm_list).value)
			{
				_index=i;
			}
		}
		$scope.page.citylist=cityArr[_index];
		console.log(matchobj('registerCity',$scope.fm_list).value)
		if(ischange)
		{
			matchobj('registerCity',$scope.fm_list).value=$scope.page.citylist[0]
		}
		else if(matchobj('registerCity',$scope.fm_list).value=='f')
		{
			matchobj('registerCity',$scope.fm_list).value='市县'
		}
		
		console.log(cityArr);
	}
	$scope.initcity();
	$scope.changeCity=function(id,ev){
		console.log(ev);
		if(id=='registerProvince')
		{
			$scope.initcity(true);
		}
	}
	
	$scope.checkform=function(){
		
//		for(var i=0;i<$scope.fm_list.length;i++)
//		{
//			
//			if($scope.fm_list[i].value=='f')
//			{
//				alert('请填写'+$scope.fm_list[i].name)
//				return false;
//			}
//			
//		}
		return true;
	}
	
	
	
	$scope.nextStep=function(){
		$rootScope._nextStep($scope.checkform(),$scope.fm_list);
	}
	
	$rootScope.callSuccessHttp();
})

app.controller('regs3Ctrl',function($scope,$http,$rootScope,BasicData,$cookieStore,$state){
	$scope.page.topOpen=true;
	$scope.page.bottomOpen=false;
	$scope.page.title='个人资料';
	$scope.page.leftNav='sqbackcom';
	$scope.page.rightNav='';
	
	$scope.model={
		tmp:'',
		minTmp:'',
		maxTmp:''
	}
	
	$scope.page.agimg2=resUrl+'wx_assets/hn/images/aghn.png'+version;
	$scope.page.agimg3=resUrl+'wx_assets/hn/images/nopic.png'+version;
	$scope.fm_list=[
		{
			title:'请上传身份证照片',
			child:[
				{
					id:'card_front',
					title:'(正)',
					value:''
				},
				{
					id:'card_con',
					title:'(反)',
					value:''
				}
			]
		},
		{
			title:'请上传户口本首页与个人页',
			child:[
				{
					id:'hukou_front',
					value:''
				},
				{
					id:'hukou_con',
					value:''
				}
			]
		},
		{
			title:'请上传学历证明',
			child:[
				{
					id:'education_pic',
					value:''
				}
			]
		},
		{
			title:'请上传工作证明',
			child:[
				{
					id:'job_pic',
					value:''
				}
			]
		},
		{
			title:'请上传房产证明',
			child:[
				{
					id:'house_pic',
					value:''
				}
			]
		},
		{
			title:'请上传有车证明',
			child:[
				{
					id:'car_pic',
					value:''
				}
			]
		}
	]
	
	if($cookieStore.get("BasicData"))
	{
		var cd=$cookieStore.get("BasicData");
	
		var tmp=[];
		for(var key in cd){
		   //key是属性,object[key]是值
		   tmp.push(key);//往数组中放属性
		}
		
		for(var i=0;i<tmp.length;i++)
		{
			var id=tmp[i];
			
			for(var y=0;y<$scope.fm_list.length;y++)
			{
				for(var z=0;z<$scope.fm_list[y].child.length;z++)
				{
					if($scope.fm_list[y].child[z].id==id)
					{
						$scope.fm_list[y].child[z].value=cd[id];
					}
				}
				
			}
		}
	}
	
	
	$scope.checkform=function(){
//		console.log($scope.fm_list);
//		for(var i=0;i<$scope.fm_list.length;i++)
//		{
//			for(var y=0;y<$scope.fm_list[i].child.length;y++)
//			{
//				if(!$scope.fm_list[i].child[y].value)
//				{
//					alert($scope.fm_list[i].title)
//					return false;
//				}
//			}
//		}
		return true;
	}

	$scope.nextStep=function(){
		$rootScope._nextStep($scope.checkform(),$scope.fm_list,function(obj){
			$rootScope.uiObj.layerloadingCtrl=true;
			var _u=buildUrl('json',"hn",'regLover',obj);
			$http.get(_u).success(function(data){
				if(data.code)
				{
					isbase=1;
//					if($rootScope.uiObj.rebuildBase==1)
//					{
//						location.reload();
////						location.href='#/pindex/0';
//					}
//					else
//					{
//						location.href='#/reg_s4';
//					}
					location.href='#/reg_s4';
					
				}
				else
				{
					layer.open({
						content:data.msg
					})
				}
				$rootScope.callSuccessHttp();
			})
		});
	}
	
	$rootScope.callSuccessHttp();
})

app.controller('regs4Ctrl',function($scope,$http,$rootScope,BasicData,$cookieStore,$state){
	$scope.page.topOpen=true;
	$scope.page.bottomOpen=false;
	$scope.page.title='个人资料';
	$scope.page.leftNav='sqbackcom';
	$scope.page.rightNav='';
	
	$scope.model={
		tmp:'',
		minTmp:'',
		maxTmp:''
	}
	
	$scope.page.agimg2=resUrl+'wx_assets/hn/images/aghn.png'+version;
	
	$scope.fm_list=[
		{
			id:'age',
			name:'年龄范围',
			type:"input",
			unit:'岁',
			data:{
				min:'f',
				max:'f'
			},
			isrange:true
		},
		{
			id:'height',
			name:"身高范围",
			type:"input",
			unit:'cm',
			data:{
				min:'f',
				max:'f'
			},
			isrange:true
		},
		{
			id:'weight',
			name:"体重范围",
			type:"input",
			unit:'kg',
			data:{
				min:'f',
				max:'f'
			},
			isrange:true
		},
		{
			id:'ceducation',
			name:"学历",
			type:'select',
			option:[
				{name:"不限",id:0},
				{name:"大专以下",id:1},
				{name:"大专",id:2},
				{name:"本科",id:3},
				{name:"硕士",id:4},
				{name:"博士",id:5}
			],
			value:'0'
		},
		{
			id:'earning',
			name:"年收入范围",
			type:'input',
			unit:'万',
			data:{
				min:'f',
				max:'f'
			},
			isrange:true
		},
		{
			id:'cprovince',
			name:"省份",
			type:'select',
			option:(function(){
				var arr=new Array(),tmp=new Object();
				for(var i=0;i<provinceArr.length;i++)
				{
					arr.push({
						name:provinceArr[i],
						id:i+1
					})
				}
				return arr;
			})(),
			value:'省份'
		},
		{
			id:'ccity',
			name:"城市",
			type:'select',
			value:'市县'
		},
		{
			id:'cmarital',
			name:"婚姻状况",
			type:'select',
			option:[
				{name:'不限',id:0},
				{name:'未婚',id:1},
				{name:'离异无子女',id:2},
				{name:'离异不带子女',id:3},
				{name:'离异带子女',id:4},
				{name:'丧偶无子女',id:5},
				{name:'丧偶有子女',id:6},
			],
			value:'0'
		}
		
	]
	
	if($cookieStore.get("BasicData"))
	{
		var cd=$cookieStore.get("BasicData");
	
		var tmp=[];
		for(var key in cd){
		   //key是属性,object[key]是值
		   tmp.push(key);//往数组中放属性
		}
		
		for(var i=0;i<tmp.length;i++)
		{
			var id=tmp[i];
			
			for(var y=0;y<$scope.fm_list.length;y++)
			{

				var _id=id.replace('cmin','').replace('cmax','').toLowerCase();
				
				if($scope.fm_list[y].id==_id)
				{
					if($scope.fm_list[y].isrange)
					{
						if(id.indexOf('cmin')>=0)
						{
							$scope.fm_list[y].data.min=cd[id]
							if($scope.fm_list[y].data.min=="")
							{
								$scope.fm_list[y].data.min='f'
							}
						}
						else if(id.indexOf('cmax')>=0)
						{
							$scope.fm_list[y].data.max=cd[id]
							if($scope.fm_list[y].data.max=="")
							{
								$scope.fm_list[y].data.max='f'
							}
						}
					}
					else
					{
						$scope.fm_list[y].value=cd[id];
						if($scope.fm_list[y].value=='')
						{
							if(id=='cprovince')
							{
								$scope.fm_list[y].value='省份';
							}
							else
							{
								$scope.fm_list[y].value='f'
							}
						}
					}
				}
			}
		}
	}
	
	$scope.initcity=function(){
		var _index;
		for(var i=0;i<provinceArr.length;i++)
		{
			if(provinceArr[i]==matchobj('cprovince',$scope.fm_list).value)
			{
				_index=i;
			}
		}
		$scope.page.citylist=cityArr[_index];
		matchobj('ccity',$scope.fm_list).value=$scope.page.citylist[0];
		console.log(cityArr);
	}
	$scope.initcity();
	$scope.changeCity=function(id,ev){
		console.log(ev);
		if(id=='cprovince')
		{
			$scope.initcity();
		}
	}
	
	$scope.checkform=function(){
		for(var i=0;i<$scope.fm_list.length;i++)
		{
			
			if($scope.fm_list[i].isrange)
			{
				if($scope.fm_list[i].data.min=='')
				{
					$.util.alert('请填写'+$scope.fm_list[i].name)
				
					return false;
				}
				
			}
			else
			{
				if(!$scope.fm_list[i].value)
				{
					$.util.alert('请填写'+$scope.fm_list[i].name)
					
					return false;
				}
				else if($scope.fm_list[i].id=='province')
				{
					if($scope.fm_list[i].value=='1')
					{
						alert('请选择'+$scope.fm_list[i].name)
						return false;
					}
				}
			}
			
			
		}
		return true;
	}
	
	
	$scope.nextStep=function(){
		$rootScope._nextStep($scope.checkform(),$scope.fm_list,function(obj){
			$rootScope.uiObj.layerloadingCtrl=true;
			var _u=buildUrl('json',"hn",'regCondition',obj);
			
			$http.get(_u).success(function(data){
				$rootScope.callSuccessHttp();
				if(data.code==0)
				{
					iscondition=1;
					
					if($rootScope.uiObj.rebuildBase==1)
					{
						location.href='#/pindex/0'
					}
					else
					{
						location.href='#/agent'
					}
					$rootScope.uiObj.rebuildBase=0;
				}
				else
				{
					layer.open({
						content:data.msg
					})
				}
				
			})
		});
	}
	
	$rootScope.callSuccessHttp();
})

app.controller('mmconditionCtrl',function($scope,$http,$rootScope,BasicData,$cookieStore,$timeout,$stateParams,$state){
	$scope.page.topOpen=true;
	$scope.page.bottomOpen=false;
	$scope.page.title='发现条件';
	$scope.page.leftNav='sqbackcom';
	$scope.page.rightNav='';
	
	provinceArr[0]='不限';
	cityArr[0][0]='不限';
	
	$scope.model={
		tmp:'',
		minTmp:'',
		maxTmp:''
	}
	
	$scope.page.agimg2=resUrl+'wx_assets/hn/images/aghn.png'+version;
	
	$scope.fm_list=[
		{
			id:'age',
			_id:'age',
			name:'年龄范围',
			type:"input",
			unit:'岁',
			data:{
				min:'f',
				max:'f'
			},
			isrange:true
		},
		{
			id:'height',
			_id:'height',
			name:"身高范围",
			type:"input",
			unit:'cm',
			data:{
				min:'f',
				max:'f'
			},
			isrange:true
		},
		{
			id:'weight',
			_id:'weight',
			name:"体重范围",
			type:"input",
			unit:'kg',
			data:{
				min:'f',
				max:'f'
			},
			isrange:true
		},
		{
			id:'ceducation',
			_id:'education',
			name:"学历",
			type:'select',
			option:[
				{name:"不限",id:'f'},
				{name:"大专以下",id:1},
				{name:"大专",id:2},
				{name:"本科",id:3},
				{name:"硕士",id:4},
				{name:"博士",id:5}
			],
			value:'f'
		},
		{
			id:'earning',
			_id:'earning',
			name:"年收入范围",
			type:'input',
			unit:'万',
			data:{
				min:'f',
				max:'f'
			},
			isrange:true
		},
		{
			id:'cprovince',
			_id:'province',
			name:"省份",
			type:'select',
			option:(function(){
				var arr=new Array(),tmp=new Object();
				for(var i=0;i<provinceArr.length;i++)
				{
					arr.push({
						name:provinceArr[i],
						id:i+1
					})
				}
				return arr;
			})(),
			value:'不限'
		},
		{
			id:'ccity',
			_id:'city',
			name:"城市",
			type:'select',
			value:'不限'
		},
		{
			id:'cmarital',
			_id:'marital',
			name:"婚姻状况",
			type:'select',
			option:[
				{name:'不限',id:'f'},
				{name:'未婚',id:1},
				{name:'离异无子女',id:2},
				{name:'离异不带子女',id:3},
				{name:'离异带子女',id:4},
				{name:'丧偶无子女',id:5},
				{name:'丧偶有子女',id:6},
			],
			value:'f'
		}
		
	]
	
	$scope.initcity=function(bool){
		var _index;
		
		for(var i=0;i<provinceArr.length;i++)
		{
			if(provinceArr[i]==matchobj('cprovince',$scope.fm_list).value)
			{
				_index=i;
			}
		}
		$scope.page.citylist=cityArr[_index];
		
		if(bool)
		{
			matchobj('ccity',$scope.fm_list).value=$scope.page.citylist[0];
		}
		else
		{
			if(matchobj('ccity',$scope.fm_list).value!='f')
			{
				console.log(matchobj('ccity',$scope.fm_list).value);
			}
			else
			{
				matchobj('ccity',$scope.fm_list).value=$scope.page.citylist[0];
			}
		}
		
		
	}
	$scope.initcity();
	$scope.changeCity=function(id,ev){
		console.log(ev);
		if(id=='cprovince')
		{
			$scope.initcity(true);
		}
	}
	
	$scope.checkform=function(){
		return true;
	}
	//获取红娘发现条件
	$scope.getmmcon=function(){
		var _u=buildUrl('json','hn','getMatchmakerCondition',{});
		$http.get(_u).success(function(response){
			console.log(response)
			$rootScope.callSuccessHttp();
			
			var cd=response;
		
			var tmp=[];
			for(var key in cd){
			   //key是属性,object[key]是值
			   tmp.push(key);//往数组中放属性
			}
			
			for(var i=0;i<tmp.length;i++)
			{
				var id=tmp[i];
				
				for(var y=0;y<$scope.fm_list.length;y++)
				{
	
					var _id=id.replace('min','').replace('max','').toLowerCase();
					if($scope.fm_list[y]._id==_id)
					{
						if($scope.fm_list[y].isrange)
						{
							if(id.indexOf('min')>=0)
							{
								$scope.fm_list[y].data.min=cd[id]
								if($scope.fm_list[y].data.min==''||!$scope.fm_list[y].data.min)
								{
									$scope.fm_list[y].data.min='f'
								}
							}
							else if(id.indexOf('max')>=0)
							{
								$scope.fm_list[y].data.max=cd[id]
								if($scope.fm_list[y].data.max==''||!$scope.fm_list[y].data.max)
								{
									$scope.fm_list[y].data.max='f'
								}
							}
						}
						else
						{
							$scope.fm_list[y].value=cd[id];
							if($scope.fm_list[y].value==''||!$scope.fm_list[y].value)
							{
								if(id=='province')
								{
									$scope.fm_list[y].value='省份';
								}
								else
								{
									$scope.fm_list[y].value='f'
								}
							}
						}
					}
				}
			}
			console.log($scope.fm_list);
			$scope.initcity();
		})
	}
	$scope.getmmcon();
	
	//设置红娘发现条件
	$scope.pushmmcon=function(){
		$rootScope._nextStep($scope.checkform(),$scope.fm_list,function(obj){
			$rootScope.uiObj.layerloadingCtrl=true;
			var _u=buildUrl('json',"hn",'regMatchmakerCondition',obj);
			
			$http.get(_u).success(function(data){
				console.log(data);
				$rootScope.callSuccessHttp();
				if(data.code==0)
				{
					$state.go('pindex',{hn:1});
				}
				else
				{
					layer.open({
						content:data.msg
					})
				}
				
			})
		},true);
	}
	
	
	
	
})

app.controller('agentCtrl',function($scope,$http,$rootScope,BasicData,$cookieStore,$state){
	$scope.page.topOpen=true;
	$scope.page.bottomOpen=false;
	$scope.page.title='注册完成';
	$scope.page.leftNav='sqbackcom';
	$scope.page.rightNav='';
	
	$scope.agentData={
		agentlist:''
	}
	
	$scope.page.agimg2=resUrl+'wx_assets/hn/images/aghn.png'+version;
	
	 if($cookieStore.get("BasicData"))
	{
		var obj={
			city:$cookieStore.get("BasicData").city
		}
	}
	var _u=buildUrl('json',"hn",'getAgentList',obj);
	$http.get(_u).success(function(data){
		$scope.agentData.agentlist=data;
		if($scope.agentData.agentlist.length!=0)
		{
			$scope.agentData.agentId=$scope.agentData.agentlist[0].id;
			$scope.agentData.agentlist[0].selected=true;
		}
		
		$rootScope.callSuccessHttp();
	})
	
	$scope.setAgent=function(){
		if($scope.agentData.agentlist&&$scope.agentData.agentlist.length!=0)
		{
			if($scope.agentData.agentId)
			{
				$rootScope.uiObj.layerloadingCtrl=true;
				var _u=buildUrl('json',"hn",'setAgent',{
					id:$scope.agentData.agentId
				});
				$http.get(_u).success(function(data){
					if(data.code==0)
					{
						isagent=1;
//						$state.go('pindex',{hn:0})
						window.location.href=serhost+'call.html?module=hn&method=index&customerId='+_customerId+'#/pindex/0';
					}
					else
					{
						$.util.alert(data.msg)
					}
					$rootScope.callSuccessHttp();
				})
			}
			
		}
		else
		{
			window.location.href=serhost+'call.html?module=hn&method=index&customerId='+_customerId+'#/pindex/0';
		}
		
	}
	
	
});

app.controller('pindexCtrl',function($scope,$http,$rootScope,BasicData,$cookieStore,$timeout,$stateParams){
	$scope.page.topOpen=true;
	$scope.page.bottomOpen=true;
	$scope.page.title='个人中心';
	$scope.page.leftNav='';
	$scope.page.rightNav='';
	
	$scope.isedit=false;  
	$scope.ishn=$stateParams.hn;   //0表示相亲用户，1表示红娘
	$rootScope.uiObj.ishn=$stateParams.hn;
	
	var deletedPics=new Array();
	
	var _u=buildUrl('json',"hn",'centerBase',{});
	$http.get(_u).success(function(data){
		
		$scope.pData=data;
		if($scope.pData.photo)
		{
			for(var i=0;i<$scope.pData.photo.length;i++)
			{
				var _u=$scope.pData.photo[i];
				var tmp={
					url:_u
				}
				$scope.pData.photo[i]=tmp;
			}
		}
		
		
		if($scope.ishn==0)
		{
			if(!$scope.pData.photo)
			{
				$scope.pData.photo=new Array();
			}
			$scope.pData.photo.push({
					type:'upload'
			})
			$scope.$watch('pData.photo',function(o,n){
					$rootScope.updateSwiper();
			},true)
		}
		
		$rootScope.callSuccessHttp();
	})
	
	$scope.gocode=function(){
		if($scope.ishn==1)
		{
			window.location.href='#/mycode';
		}	
	}
	
	$scope.editpic=function(){
		
		var len=$scope.pData.photo.length;
		if(len==1)
		{
			$.util.alert('请上传照片')
		}
		else
		{
			$scope.isedit=true;  
			for(var i=0;i<len;i++)
			{
				if(i!=len-1)
				{
					$scope.pData.photo[i].isedit=true;
				}
				
			}
			console.log($scope.pData.photo)
		}
	}
	$scope.savepic=function(){
		
		var init=function(){
			var len=$scope.pData.photo.length;
			for(var i=0;i<len;i++)
			{
				if(i!=len-1)
				{
					$scope.pData.photo[i].isedit=false;
				}
					
			}
			$scope.isedit=false; 
		}
		
		if(deletedPics.length!=0)
		{
			$rootScope.uiObj.layerloadingCtrl=true;
			var _u = buildUrl('json', "hn", 'delPhoto', deletedPics);
			$http.get(_u).success(function(data) {
				deletedPics=new Array();
				$rootScope.callSuccessHttp();
				if(data.code == 0) {
					init();
					$.util.alert('删除成功');
				} else {
					$.util.alert(data.msg)
				}
			
			})
		}
		else
		{
			init();
		}
		
		
		
		
		
	}
	$scope.deletepic=function(index,url){
		deletedPics.push(url);
		$scope.pData.photo.splice(index,1);
		console.log(deletedPics);
	}
});

app.controller('mycodeCtrl',function($scope,$http,$rootScope,BasicData,$cookieStore,$timeout){
	$scope.page.topOpen=true;
	$scope.page.bottomOpen=false;
	$scope.page.title='我的二维码';
	$scope.page.leftNav='sqbackcom';
	$scope.page.rightNav='';
	
	$scope.codeData={};
	$scope.codeData.heart=resUrl+'wx_assets/hn/images/heart.png'+version;
//	$scope.codeData.code=resUrl+'wx_assets/hn/images/mycode-test.png'+version;
	
	var _link=buildUrl('json',"hn",'centerQrcode',{});
	
	$http.get(_link).success(function(response){
		$scope.codeData.code=response.qrcode;
		$rootScope.callSuccessHttp();
	})
	
	

	
});


app.controller('lovemeCtrl',function($scope,$http,$rootScope,BasicData,$cookieStore,$timeout){
	$scope.page.topOpen=true;
	$scope.page.bottomOpen=false;
	$scope.page.title='对我感兴趣的人';
	$scope.page.leftNav='sqbackcom';
	$scope.page.rightNav='';
	
	$scope.loveMe={
		dropData:''
	}

});
app.controller('loveeachCtrl',function($scope,$http,$rootScope,BasicData,$cookieStore,$timeout){
	$scope.page.topOpen=true;
	$scope.page.bottomOpen=false;
	$scope.page.title='互相关注的人';
	$scope.page.leftNav='sqbackcom';
	$scope.page.rightNav='';
	
	$scope.loveMe={
		dropData:''
	}
	
});

app.controller('discoverCtrl',function($scope,$http,$rootScope,BasicData,$cookieStore,$timeout,$stateParams){
	$scope.page.topOpen=true;
	$scope.page.bottomOpen=true;
	$scope.page.title='发现';
	$scope.page.leftNav='sqbackcom';
	$scope.page.rightNav='';
		
	if($stateParams.hn==0)
	{
		var method='discover';
		$rootScope.uiObj.hn=0;
	}
	else if($stateParams.hn==1)
	{
		var method='matchmakerDiscover';
		$rootScope.uiObj.hn=1;
	}
	var _u=buildUrl('json',"hn",method,{});
	$http.get(_u).success(function(data){
		console.log(data);
		$scope.discoverlist=data.results;
		$scope.imgres={
			discover_default:resUrl+'wx_assets/hn/images/discover_default.jpg'+version,
			online:resUrl+'wx_assets/hn/images/online.png'+version,
			unline:resUrl+'wx_assets/hn/images/unline.png'+version,
			discover_null:resUrl+'wx_assets/hn/images/discover_null.png'+version
		}
		$rootScope.callSuccessHttp();
	})
	
});

app.controller('fmatchCtrl',function($scope,$http,$rootScope,BasicData,$cookieStore,$timeout){
	$scope.page.topOpen=true;
	$scope.page.bottomOpen=false;
	$scope.page.title='我介绍的人';
	$scope.page.leftNav='sqbackcom';
	$scope.page.rightNav='sqlink';
	$scope.page.rightTlink='未注册的人';
	$scope.fmatch={
		dropData:''
	}
});

app.controller('unregCtrl',function($scope,$http,$rootScope,BasicData,$cookieStore,$timeout){
	$scope.page.topOpen=true;
	$scope.page.bottomOpen=false;
	$scope.page.title='未注册的人';
	$scope.page.leftNav='sqbackcom';
	$scope.page.rightNav='';
	
	$scope.unreg={
		dropData:''
	}
});

app.controller('loveIndexCtrl',function($stateParams,$scope,$http,$rootScope,BasicData,$cookieStore,$timeout){
	$scope.page.topOpen=true;
	$scope.page.bottomOpen=false;
	$scope.page.title='个人主页';
	$scope.page.leftNav='sqbackcom';
	$scope.page.rightNav='';
	refereeId='';
	
	var mybase=JSON.parse(_USERINFO);
	
	$scope.imgres={
			online:resUrl+'wx_assets/hn/images/online.png'+version,
			unline:resUrl+'wx_assets/hn/images/unline.png'+version,
			discover_null:resUrl+'wx_assets/hn/images/discover_null.png'+version
	}
	var userid=(_uid?_uid:mybase.matchmaker.uid);
	if(userid&&$stateParams.uid!=userid)
	{
		refereeId='&refereeId='+userid;
	}
	var shareUser=function(title,desc,imgUrl){
		//分享
		var shareUrl=serhost+'call.html?module=hn&method=index&customerId='+_customerId+refereeId+'#/loveIndex/'+$stateParams.uid;
		console.log(shareUrl);
		shareData.title=title;
		shareData.desc=desc;
		shareData.link=shareUrl;
		shareData.imgUrl=imgUrl;
		wx_share.init(shareData);
	}
	
//	var refere=function(){
//		var _link=buildUrl('json','hn','regLover',{
//			refereeId:_refereeId
//		})
//		if(_refereeId)
//		{
//			$http.get(_link).success(function(data){
//				if(!data.code)
//				{
//					layer.open({
//						content:data.msg
//					})
//				}
//			})
//		}
//		
//	}
//	refere();
	
	var _u=buildUrl('json',"hn",'loveIndex',{
		uid:$stateParams.uid
	});
	$http.get(_u).success(function(data){
		console.log(data);
		$scope.lData=data;
		$scope.picgroup=new Array();
		for(var i=0;i<$scope.lData.photo.length;i++)
		{
			if(!$scope.picgroup[parseInt(i/4)])
			{
				$scope.picgroup[parseInt(i/4)]={
					list:new Array()
				}
			}
			$scope.picgroup[parseInt(i/4)].list.push($scope.lData.photo[i]);
		}
		for(var i=0;i<$scope.picgroup.length;i++)
		{
			if($scope.picgroup[i].list.length<4)
			{
				var len=$scope.picgroup[i].list.length;
				for(var y=3;y>=(4-len);y--)
				{
					$scope.picgroup[i].list.push("");
				}
			}
		}
		var desc='一起做红娘微信相亲平台',
			sex=(function(gender){
				switch(gender)
				{
					case '1':
						results='男';
						break;
					case '2':
						results='女';
						break;
				}
				return results;
			})(data.gender),
			birthday=data.birthday.split('-')[0],
			height=data.height,
			weight=data.weight,
			city=data.province+'-'+data.city,
			education=(function(education){
				var arr=['大专以下','大专','本科','硕士','博士'];
				for(var i=0;i<=arr.length;i++)
				{
					if(education==i)
					{
						results=arr[i]
					}
				}
				return results;
			})(data.education),
			job=(function(job){
				var arr=['计算机/互联网/通信','公务员/事业单位','教师','医生','护士','空乘人员','生产/工艺/制造','商业/服务业/个体经营','金融/银行/投资/保险','文化/广告/传媒','娱乐/艺术/表演','律师/法务','教育/培训/管理咨询','建筑/房地产/物业','酒店/旅游','农业','在校学生']
				for(var i=1;i<=arr.length;i++)
				{
					if(job==i)
					{
						results=arr[i];
					}
				}
				return results;
			})(data.job),
			title='【一起做红娘相亲嘉宾】'+sex+'，'+birthday+'年，'+height+'厘米，'+weight+'公斤，'+education+'，'+job+'，'+city;
		shareUser(title,desc,(data.headimgurl?data.headimgurl:data.photo[0]));
		$rootScope.callSuccessHttp();
		
	})
	
});

app.controller('accountCtrl',function($scope,$http,$rootScope,BasicData,$cookieStore,$timeout,$stateParams){
	$scope.page.topOpen=true;
	$scope.page.bottomOpen=false;
	$scope.page.title='我的账户';
	$scope.page.leftNav='sqbackcom';
	$scope.page.rightNav='';
	
	$scope.ishn=$stateParams.hn;   //0表示相亲用户，1表示红娘
	
	$scope.account={
		type:$scope.ishn==0?'centerAccount':'matchmakerAccount',
		data:JSON.parse(_USERINFO)
	}
	$scope.loveMe={
		dropData:''
	}
	
	
});

app.controller('withdrawCtrl',function($scope,$http,$rootScope,BasicData,$cookieStore,$timeout,$stateParams){
	$scope.page.topOpen=true;
	$scope.page.bottomOpen=false;
	$scope.page.title='我的账户';
	$scope.page.leftNav='sqbackcom';
	$scope.page.rightNav='';
	
	$scope.tx=function(){
		
		if($scope.money)
		{

			var _link=buildUrl('json','hn','withdraw',{
				money:$scope.money
			})
			$rootScope.uiObj.layerloadingCtrl=true;
			$http.get(_link).success(function(response){
				$rootScope.callSuccessHttp();
				$.util.alert(response.msg);
				if(response.code==0)
				{
					location.reload();
				}
				
			})
		}
		else
		{
			$.util.alert('请输入金额');
		}
	}
});

app.controller('rechargeCtrl',function($scope,$http,$rootScope,BasicData,$cookieStore,$timeout,$stateParams,$state){
	$scope.page.topOpen=true;
	$scope.page.bottomOpen=false;
	$scope.page.title='我的账户';
	$scope.page.leftNav='sqbackcom';
	$scope.page.rightNav='';
	
	
	
	var _link2=buildUrl('json','hn','packageList',{
	})
	$http.get(_link2).success(function(response){
		$scope.packageList=response;
		$rootScope.callSuccessHttp();
	})
	
	$scope.recg=function(id){
		$rootScope.uiObj.layerloadingCtrl=true;
		var _link=buildUrl('json','hn','recharge',{
			id:id
		})
		$http.get(_link).success(function(response){
			
			var url = serhost+'Wxpay/getWxPayParam.json?customerId='+_customerId,
            data = {
                	sn:0,
                    desc:response.msg.desc,
                    productFee:response.msg.productFee,
                    module:response.msg.module,
                    moduleId:response.msg.moduleId,
                    transportFee:response.msg.transportFee,
                    userName:response.msg.userName,
                    method:response.msg.method
            },
            transFn = function(data) {
                return $.param(data);
            },
            postCfg = {
                headers: { 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'},
                transformRequest: transFn
            };
			
			$http.post(url, data, postCfg)
            .success(function(d){
            	$rootScope.callSuccessHttp();
            	if (d.code) {
                    $.util.alert(d.msg);
                    return;
                }
               	WeixinJSBridge.invoke('getBrandWCPayRequest', d.pkg, function(res) {
                        console.log(res.err_msg);
                        if (res.err_msg == 'get_brand_wcpay_request:ok') {
                        		location.href='#/account/0'
                        } else  {
                            var res = res; 	
                            if (res.err_msg == 'get_brand_wcpay_request:cancel') {
                                return alert("操作已取消"), void 0
                            } else if (res.err_msg == 'get_brand_wcpay_request:fail') {
                                return alert("网络错误发送失败，请稍后再试"), void 0
                            } else if (res.err_msg == 'access_control:not_allow' || res.err_msg == 'system:access_denied') {
                                return alert("商家尚未开通微信支付"), void 0
                            } else {
                                return alert(res.err_msg), void 0
                            }                                   
                        }
                    });
            });
		})
		
		
		
	}
	
});

